package com.episode.duetapi.service.impl;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.episode.duetapi.exceptionHandle.CustomerException;
import com.episode.duetapi.mapper.AdminMapper;
import com.episode.duetapi.model.Admin;
import com.episode.duetapi.service.AdminService;
import com.episode.duetapi.utils.JwtHelper;
import com.episode.duetapi.utils.ResultCode;

import io.jsonwebtoken.Claims;

@Service
public class AdminServiceImpl implements AdminService{
	
	@Autowired
	private AdminMapper adminMapper;

	@Override
	public Admin loginByUser(String userName, String passWord) {
		Admin admin = new Admin();
		admin.setUsername(userName);
		admin.setPassword(passWord);
		return adminMapper.loginByUser(admin);
	}
	
	 public static void main (String[] args) throws CustomerException{
	    
	        	String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwidXNlck5hbWUiOiJhZG1pbiIsInJvbGVJZCI6MSwiaXNzIjoiZXBpc29kZSIsImF1ZCI6ImFkbWluJCMjIn0.Y1tDSDhU1wJ4MeuMxgOhSqWUUlLltGL1JFsfGwLniWA";
	        	String token2 = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwidXNlck5hbWUiOiJhZG1pbiIsInJvbGVJZCI6MSwiaXNzIjoiZXBpc29kZTE1NDQ3NzgwNTM3NDAiLCJhdWQiOiJhZG1pbiQjIyJ9.fViVh84H02QP3S4AE8LgFOlRtKjs0Q7-vXETLwQKA88";
	        			//request.getHeader("Authorization");
	            Claims claims = JwtHelper.parseJWT(token);
	            int userId = (int) claims.get("id");
	            System.out.println(userId);
	            
	            Claims claims2 = JwtHelper.parseJWT(token);
	            int userId2 = (int) claims.get("id");
	            System.out.println(userId2);
	        
	 }

}
	 
